
import 'package:enjoy_plus_three/pages/home/detail.dart';
import 'package:enjoy_plus_three/pages/login/index.dart';
import 'package:enjoy_plus_three/pages/profile/index.dart';
import 'package:enjoy_plus_three/pages/tab_bar/index.dart';
import 'package:enjoy_plus_three/utils/token.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    routes: {
      '/': (context) => const TabBarPage(),
      '/detail': (context) => const NoticeDetail(),
    },
    initialRoute: '/',
        onGenerateRoute: (settings) {
      final tokenManager = TokenManager();
      final token = tokenManager.getToken() ?? '';
      if (token.isEmpty && settings.name != '/login') {
        return MaterialPageRoute(builder: (context) => const LoginPage());
      }

      if (settings.name == '/profile') {
        return MaterialPageRoute(builder: (context) => const ProfilePage());
      }

      return null;
    },
  ));
}